//! Implementation of the TachometerObserver class
/*!
	\file TachometerObserver.cpp
	\author Andreas Lehner
	\date 22.11.2012

*/
#include "TachometerObserver.h"

TachometerObserver::TachometerObserver(PKW * automobile){
	mAutomobile = automobile;
	//login -> registrate in observer list
	mAutomobile->Attach(this);
	mDisplay = new AnalogDisplay();
}

TachometerObserver::~TachometerObserver(){
	//logout -> leave observer list
	mAutomobile->Detach(this);
	mAutomobile = 0;
	delete mDisplay; mDisplay = 0;
}

void TachometerObserver::Update(){
	//get current speed of automobile
	mSpeed = mAutomobile->GetCurrentSpeed();
	//update value on an analog display
	if (!mDisplay->SendValue((int)mSpeed)){
		throw std::exception("Speed value could not be sent to AnalogDisplay!");
	}
}